Skip to content

Resolve reduce/reduce conflicts in grammar rule order - #869

Merged
ydah merged 1 commit into
masterfrom
fix/reduce-reduce-rule-order
Nov 11, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/reduce-reduce-rule-order

Conversation

@ydah

@ydah ydah commented Nov 11, 2026

Copy link
Copy Markdown
Member

Context#compute_yydefact assumes reductions are stored in grammar order, but state construction collects kernel items before closure items. When an earlier empty rule competes with a later completed rule, this can select the later rule in a reduce/reduce conflict.

Sort reductions by rule ID before writing actions in reverse order, so the first rule in the grammar wins, following Bison's conflict resolution rule (https://www.gnu.org/software/bison/manual/html_node/Reduce_002fReduce.html).

For example:

start: 'a' empty 'b' 'x' | direct 'b' 'y';
empty: %empty;
direct: 'a';

Both LALR and IELR parsers previously rejected abx and accepted aby. They now accept abx and reject aby, matching Bison 3.8.2. Add table-level regression tests for both rule declaration orders and generated-parser tests for both LR types.

@ydah
ydah merged commit 2deea70 into master Nov 11, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant